package cate.game.admin.menu.rank;

import cate.common.table.rank.row.RankBaseRow;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.rank.h.IRankFuncHandler;
import cate.game.rank.history.RankReachHistory;
import cate.game.rank.vo.RankParam;
import cate.game.role.farm.rank.UnrealRankObj;

import java.util.Map;

public class RankMenu extends MenuSetup {
    public RankMenu(String type) {
        super(type);
    }

    public RankMenu(GameBody game) {
        super("排行榜");

        reg(game, "清空某个排行榜数据", 1, "排行榜ID", (role, params) -> {
            int rankId = Integer.parseInt(params.get(0));
            RankBaseRow base = role.getGame().table.rank.base.get(rankId);
            if (base == null) {
                game.notice.message(role, "该排行榜不存在");
                return;
            }
            if (base.type == RankBaseRow.CROSS) {
                game.notice.message(role, "无法删除跨服排行榜数据");
                return;
            }
            IRankFuncHandler handler = game.rank.getRankHandler(rankId);
            if (handler == null) {
                game.notice.message(role, "排行榜怎么不见了呢");
                return;
            }
            handler.getRankList(new RankParam()).clear();
            Map<Integer, RankReachHistory> hisMap = game.rank.getRankHistory(rankId);
            if (!hisMap.isEmpty()) {
                hisMap.clear();
            }
            UnrealRankObj obj = role.getFarm().rank.unrealObjs.get(rankId);
            if (obj != null) {
                obj.rewardGot.clear();
            }
            role.getFarm().rank.noticeUpdate();
            game.notice.message(role, "删除成功，请重新打开排行榜");
        });

        reg(game, "清空我的领奖记录", 0, "", (role, params) -> {
            role.getFarm().rank.unrealObjs.values().forEach(e -> e.rewardGot.clear());
            role.getFarm().rank.noticeUpdate();
            game.notice.message(role, "清除成功");
        });
    }
}
